package com.scedu.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.scedu.springcloud.handler.CustomerBlockHandler;
import com.scedu.springcloud.service.OrderFeignService;
import com.scedu.springcloud.springcloud.entity.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
class OrderController {

    @Autowired
    OrderFeignService orderFeignService;

    @Value("${server.port}")
    private String port;


    @RequestMapping(value = "/consumer/get/{id}", method = RequestMethod.GET)
    @SentinelResource(value = "get",
            blockHandlerClass =CustomerBlockHandler.class, //自定义限流处理类
            blockHandler = "handlerException1",
            fallbackClass =CustomerBlockHandler.class, //自定义限流处理类
            fallback = "fallbackException1")  //自定义限流处理类中的方法
    public CommonResult get(@PathVariable Long id) {
        CommonResult result = orderFeignService.getPaymentById(id);
        if (id==4) {
            throw new IllegalArgumentException("非法参数");
            }
            else if (result.getData()==null){
            throw new NullPointerException("空数据异常");
        }

        return new CommonResult(200,port+" from order data is ",result);

    }


}
